/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PanelModificarPrestacion.java
 *
 * Created on 9/04/2011, 04:38:42 PM
 */

package frontera.interfaz.panel;

import control.SIRHApp;
import entidad.Prestacion;
import frontera.interfaz.panel.herramientas.PanelHerramientasBuscar;

/**
 *
 * @author Sebastian
 */
public class PanelModificarPrestacion extends javax.swing.JPanel {

    /** Creates new form PanelModificarPrestacion */
    public PanelModificarPrestacion(Prestacion prestacion) {
        initComponents();
        inicializarVariables(prestacion);
    }

    private void inicializarVariables(Prestacion prestacion){
        fieldNombre.setText(prestacion.getNombre());
        fieldPorEmpleado.setText(prestacion.getPorcentajeEmpleado());
        fieldPorCompañia.setText(prestacion.getPorcentajeCompañia());
        this.prestacion=prestacion;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        iconoModificar = new javax.swing.JLabel();
        titulo1 = new javax.swing.JLabel();
        titulo2 = new javax.swing.JLabel();
        botonGuardar = new javax.swing.JButton();
        botonCancelar = new javax.swing.JButton();
        labelResultado = new javax.swing.JLabel();
        panelDatosBasicos = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        labelNombre = new javax.swing.JLabel();
        fieldNombre = new javax.swing.JFormattedTextField();
        jPanel2 = new javax.swing.JPanel();
        fieldPorEmpleado = new javax.swing.JFormattedTextField();
        labelPorcentaje = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        fieldPorCompañia = new javax.swing.JFormattedTextField();
        labelPorCompañia = new javax.swing.JLabel();

        iconoModificar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/frontera/recursos/UpdIndicadores.png"))); // NOI18N

        titulo1.setFont(new java.awt.Font("Dialog", 1, 32));
        titulo1.setText("Editando ");

        titulo2.setFont(new java.awt.Font("Dialog", 1, 32));
        titulo2.setText("Prestacion");

        botonGuardar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/frontera/recursos/Save.png"))); // NOI18N
        botonGuardar.setText("Guardar");
        botonGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonGuardarActionPerformed(evt);
            }
        });

        botonCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/frontera/recursos/Cancelar.png"))); // NOI18N
        botonCancelar.setText("Cancelar");
        botonCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonCancelarActionPerformed(evt);
            }
        });

        labelResultado.setFont(new java.awt.Font("Dialog", 0, 12));
        labelResultado.setText(" ");

        panelDatosBasicos.setBorder(javax.swing.BorderFactory.createTitledBorder("Datos Básicos"));
        panelDatosBasicos.setLayout(new java.awt.GridLayout(0, 1));

        labelNombre.setText("Nombre");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(labelNombre, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(fieldNombre, javax.swing.GroupLayout.DEFAULT_SIZE, 536, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelNombre)
                    .addComponent(fieldNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        panelDatosBasicos.add(jPanel1);

        labelPorcentaje.setText("Porcentaje Empleado");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(labelPorcentaje)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(fieldPorEmpleado, javax.swing.GroupLayout.DEFAULT_SIZE, 533, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelPorcentaje)
                    .addComponent(fieldPorEmpleado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        panelDatosBasicos.add(jPanel2);

        labelPorCompañia.setText("Porcentaje Compañia");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(labelPorCompañia)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(fieldPorCompañia, javax.swing.GroupLayout.DEFAULT_SIZE, 532, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelPorCompañia)
                    .addComponent(fieldPorCompañia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        panelDatosBasicos.add(jPanel3);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(iconoModificar)
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(titulo2)
                            .addComponent(titulo1)))
                    .addComponent(panelDatosBasicos, javax.swing.GroupLayout.DEFAULT_SIZE, 676, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(botonGuardar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(botonCancelar))
                    .addComponent(labelResultado, javax.swing.GroupLayout.PREFERRED_SIZE, 652, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(iconoModificar))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(34, 34, 34)
                        .addComponent(titulo1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(titulo2)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panelDatosBasicos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(labelResultado, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(botonCancelar)
                    .addComponent(botonGuardar))
                .addContainerGap(118, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void botonGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonGuardarActionPerformed
         

        String resultadoOperacion = SIRHApp.getInstance().getAdmPrestaciones().actualizarPrestacion(prestacion, fieldNombre.getText(), 
                                        fieldPorEmpleado.getText(),
                                        fieldPorCompañia.getText());

        if(resultadoOperacion.equals("")){
            SIRHApp.getInstance().getVentanaPrincipal().setPanelNominaPrestaciones(SIRHApp.getInstance().getVentanaPrincipal().getPanelPrestaciones());
            //Dejar la búsqueda del panel anterior en blanco
            ((PanelHerramientasBuscar<Prestacion>) SIRHApp.getInstance().getFactoryInterfaz().getPanelPrestaciones().getPanelHerramientas()).inicializarBusqueda();
            SIRHApp.getInstance().getVentanaPrincipal().getPanelPrestaciones().actualizarLista(SIRHApp.getInstance().getSistema().getPrestaciones());
        }
        else{
            labelResultado.setText(resultadoOperacion);
        }
    }//GEN-LAST:event_botonGuardarActionPerformed

    private void botonCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonCancelarActionPerformed
        SIRHApp.getInstance().getVentanaPrincipal().setPanelNominaPrestaciones(SIRHApp.getInstance().getVentanaPrincipal().getPanelPrestaciones());
        //Dejar la búsqueda del panel anterior en blanco
            ((PanelHerramientasBuscar<Prestacion>) SIRHApp.getInstance().getFactoryInterfaz().getPanelPrestaciones().getPanelHerramientas()).inicializarBusqueda();
            SIRHApp.getInstance().getVentanaPrincipal().getPanelPrestaciones().actualizarLista(SIRHApp.getInstance().getSistema().getPrestaciones());
    }//GEN-LAST:event_botonCancelarActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton botonCancelar;
    private javax.swing.JButton botonGuardar;
    private javax.swing.JFormattedTextField fieldNombre;
    private javax.swing.JFormattedTextField fieldPorCompañia;
    private javax.swing.JFormattedTextField fieldPorEmpleado;
    private javax.swing.JLabel iconoModificar;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JLabel labelNombre;
    private javax.swing.JLabel labelPorCompañia;
    private javax.swing.JLabel labelPorcentaje;
    private javax.swing.JLabel labelResultado;
    private javax.swing.JPanel panelDatosBasicos;
    private javax.swing.JLabel titulo1;
    private javax.swing.JLabel titulo2;
    // End of variables declaration//GEN-END:variables
    private Prestacion prestacion;
}
